package services;

import helpers.ValidateHelper;

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entities.BlockCustomer;

import models.BlockCustomerModel;

public class RemoveBlockCustomer extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		
		//Get customer
		String path = ((HttpServletRequest) request).getRequestURI();
		String customer = URLDecoder.decode(path.replaceAll(request.getServletPath() + "/", ""),"UTF-8");
		
		if (customer != null && ValidateHelper.isEmail(customer)) {
			BlockCustomerModel blockCustomerModel = BlockCustomerModel.getInstance();
			BlockCustomer blockCustomer = blockCustomerModel.get(customer);
			if (blockCustomer != null) {
				blockCustomerModel.delete(blockCustomer);
			}
			
			response.setContentType("text/html");
			response.getWriter().println("Remove success " + customer + " to block customer");
		} else {
			
			response.setContentType("text/html");
			response.getWriter().println("Customer is not valid email.");
		}
		
	}
}
